export let ajax = function(url, data, callback, method = 'get') {
    let x = new XMLHttpRequest();
    let arr = Object.keys(data);
    let newArr = arr.map(item => `${item}=${data[item]}`);
    let str = newArr.join('&');
    if (method === 'get') {
        x.open(method, url + '?' + str);
        x.send();
    }else{
        x.open(method,url);
        x.setRequestHeader('Content-type','application/x-www-form-urlencoded')
        x.send(str)
    }
    x.onreadystatechange = function () {
        if (x.readyState === 4) {
            if (x.status >= 200 && x.status < 300) {
                let obj = x.response;
                callback(obj)
            }
        }
    }
}